home *** CD-ROM | disk | FTP | other *** search
/ Clipper Collection / Clipper Collection.iso / clipper7 / nannws36.arc / SIZEFILE.PRG < prev    next >
Text File  |  1989-05-01  |  2KB  |  64 lines

  1. * Function: Size_file
  2. * Author:   David Morgan
  3. * Version:  Clipper Summer '87
  4. *
  5. * Copyright (c) 1989 Nantucket Corp.  All Rights Reserved.
  6. *
  7. * Note(s):  Given a valid file handle, returns the size of the
  8. *           file.  Given additionally an optional number-of-bytes
  9. *           by which to change file's size, extends or truncates
  10. *           the file and returns the new size.
  11. *
  12. *           If the number of bytes is positive, the file is
  13. *           extended; if negative, truncated.  Truncating more
  14. *           bytes than file contains produces no error, leaves
  15. *           filesize unchanged.  The content of extended bytes is
  16. *           indeterminate.
  17. *
  18. *           Returns -1 if an error occurs.
  19. *
  20. *
  21. *           "[FSEEK] method 2 can move the file pointer either
  22. *           forward or backward from the end of the file...." 
  23. *
  24. *           "specifying method code 02H with an offset of 0
  25. *           conveniently positions the file pointer at the end of
  26. *           the file.  With method code 02H offset 0, the size of
  27. *           the file can also be determined by examining the
  28. *           pointer position returned by the function."
  29. *
  30. *           "[If FWRITE's] number of bytes to write [... is] 0,
  31. *           the file is truncated or extened to the current file
  32. *           pointer loaction."
  33. *
  34. *           - The MS-DOS Encyclopedia, Microsoft Press,
  35. *                  pp. 1308, 1312, 1313.
  36. *
  37. FUNCTION Size_file
  38. PARAMETERS hndl, how_many
  39. PRIVATE f_ok, newsize
  40. how_many = IIF(PCOUNT() != 2, 0, how_many)
  41. f_ok = .T.
  42. FSEEK(hndl,how_many,2)          && Move pointer from EOF position.
  43. f_ok = f_ok .AND. (FERROR()=0)
  44. FWRITE(hndl,'',0)               && Coincide EOF with new position.
  45. f_ok = f_ok .AND. (FERROR()=0)
  46. newsize = FSEEK(hndl,0,2)       && Measure new size.
  47. f_ok = f_ok .AND. (FERROR()=0)
  48. RETURN  IIF(f_ok, newsize, -1)
  49.  
  50.  
  51. * Function: File_size
  52. * Author:   David Morgan
  53. * Version:  Clipper Summer '87
  54. * Copyright (c) 1989 Nantucket Corp. All Rights Reserved.
  55. *
  56. * Note(s):  Given a valid file handle, returns the size of the
  57. *           file, or -1 if an error occurs.
  58. *
  59. FUNCTION File_size
  60. PARAMETERS hndl
  61. PRIVATE size
  62. size = FSEEK(hndl,0,2)
  63. RETURN IIF(FERROR()=0, size, -1)
  64.